<template>
  <!-- 前台配件查询 -->
  <div>
    <TopFilter :list="topFilterList" :cols="4" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      columnsRef="frontPartsInquiryColumnswsss"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :isSelectColumn="false"
      :isExportExcel="true"
      exportFileName="前台配件查询.xlsx"
    >
      <!-- :fetchapi="fetchApi" -->
      <template slot="controls" slot-scope="props">
        <!-- <AjaxButton :click="pushDialog" type="primary">发布</AjaxButton>
        <AjaxButton :click="offlineDialog" type="primary">下线</AjaxButton>  -->
      </template>
    </FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getPartsList } from '@/api/part/report/frontPartsInquiry';
import PartNoQuery from '@/pages/part/report/replaceAndInventory/';
export default {
  name: 'ReplaceAndInventory',
  components: { PartNoQuery },
  mixins: [dictionary],
  props: [],
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      columns: this.createTableList(),
      fetchParams: { xhrAbort: true },
      fetchApi: getPartsList,
      exportBtn: false,
      printBtn: false,
      searchBtn: false,
      visible: false
    };
  },
  methods: {
    // 关闭弹窗
    closeDialog() {
      this.visible = false;
    },
    // 点击配件进行搜索
    searchPartsHandle() {
      this.visible = true;
    },
    // 曾查配件号
    handleSearch() {
      this.visible = true;
    },
    // 打印处理
    handlePrint() {},
    // 导出处理
    handleExport() {},
    // 展开收起调用函数
    collapseHandle() {},
    // 搜索条件改变调用方法
    changeHandle(val) {
      if (!val['partNo'] & !val['partName'] & !val['mainGroupNo']) {
        return this.$notify.warning({ title: '提示信息', message: '[主组号]或[配件代码]或[配件名称],必须输入至少两位!' });
      }
      this.fetchParams.xhrAbort = true;
      this.fetchParams = Object.assign({}, { xhrAbort: false }, val);
    },
    // 创建表单字段列表
    createTableList() {
      return [
        {
          title: '配件代码',
          dataIndex: 'partNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: '160',
          showOverflowTooltip: true
        },
        {
          title: '配件名称',
          dataIndex: 'partName',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '拼音码',
          dataIndex: 'spellCode',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        // {
        //   title: '批号',
        //   dataIndex: '',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '保质期截止日期',
          dataIndex: 'shelfDays',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true
        },
        {
          title: '仓库代码',
          dataIndex: 'storageCode',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '仓库名称',
          dataIndex: 'storageName',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '含税销售单价',
          dataIndex: 'notTaxInstructPrice',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true
        },
        {
          title: '库存数量',
          dataIndex: 'stockQuantity',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true
        },
        {
          title: '可用数量',
          dataIndex: 'useableStock',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true
        },
        {
          title: '计量单位',
          dataIndex: 'unitName',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '可用',
          dataIndex: 'isDisable',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8131'),
          dictItems: this.createDictList('8131'),
          render: props => {
            return <span>{this.createDictText(props.row.isDisable, '8131')}</span>;
          },
          showOverflowTooltip: true
        },
        {
          title: '不含税库存成本单价',
          dataIndex: 'costPrice',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true
        },
        {
          title: '车型代码',
          dataIndex: 'modelCode',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '车型名称',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        }
        // {
        //   title: '网络代码',
        //   dataIndex: '',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '网络名称',
        //   dataIndex: '',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // }
      ];
    },
    // 创建筛选条件
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'partNo',
          placeholder: ''
          // unitRender: () => {
          //   return <el-button slot="append" icon="el-icon-search" onClick={this.searchPartsHandle}></el-button>;
          // }
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'partName',
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '主组号',
          fieldName: 'mainGroupNo',
          placeholder: ''
        }
      ];
    }
  }
};
</script>

<style></style>
